import request from '@/utils/request'
import { setToken,getToken } from '@/utils/auth'
// 请求登陆接口
export function login(name, pw) {
  return request({
    // url: 'http://ai7avd.natappfree.cc/tourism/platform/back/Admin/login',
    url: 'http://qjx86z.natappfree.cc/tourism/platform/back/Admin/login',
    method: 'post',
    data: {
      account: name,
      password: pw
    }
  })
}

export function getInfo() {
  return request({
    url: '/api/admin/login',
    method: 'get',
  })
}

export function logout() {
  return request({
    url: '/admin/logout',
    method: 'post'
  })
}
// 请求用户列表接口
export function fetchList(params) {
  return request({
    url: '/api/admin/userList',
    method: 'post',
    data: {
      token: getToken(),
      size: params.pageSize,
      page: params.pageNum
    }
  })
}

export function createAdmin(data) {
  return request({
    url: '/admin/register',
    method: 'post',
    data: data
  })
}

export function updateAdmin(id, data) {
  return request({
    url: '/admin/update/' + id,
    method: 'post',
    data: data
  })
}

// 请求用户是否禁用接口
export function updateStatus(id) {
  return request({
    url: '/api/admin/userAccountBan',
    method: 'post',
    data: {
      token: getToken(),
      id: id
    }
  })
}
// 请求删除用户接口
export function deleteAdmin(id) {
  return request({
    url: 'api/admin/userAccountDelete',
    method: 'post',
    data: {
      token: getToken(),
      id: id
    }
  })
}

export function getRoleByAdmin(id) {
  return request({
    url: '/admin/role/' + id,
    method: 'get'
  })
}

export function allocRole(data) {
  return request({
    url: '/admin/role/update',
    method: 'post',
    data: data
  })
}
